<template>
  <div>
    <button type="button" class="btn btn-success" @click="toAdd">添加</button>
    <table class="table table-striped">
      <thead>
        <tr>
          <th>编号</th>
          <th>名称</th>
          <th>日期</th>
          <th>介绍</th>
          <th>类别</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="p in papers" :key="p.tid">
          <td>{{p.gid}}</td>
          <td>{{p.gname}}</td>
          <td>{{p.gdate | dateFmt}}</td>
          <td>{{p.ginfo}}</td>
          <td>{{p.cname}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import moment from 'moment'
export default {
  filters:{
    "dateFmt":function(str){
      return moment(str).format('YYYY-MM-DD');
    }
  },
  data(){
    return {
      papers:[]
    }
  },
  methods:{
    initpapers(){
      this.$ajax({
        url:'paper',
        method:'get'
      }).then(resp=>{
        this.papers = resp.data.message
      })
    },
    toAdd(){
      this.$router.push('/add');
    }
  },
  created(){
    this.initpapers();
  }
}
</script>

<style scoped>

</style>